import 'package:json_annotation/json_annotation.dart';

part 'git_branch.g.dart';

@JsonSerializable()
class GitBranch {
  final String name;
  final CommitData commit;
  final bool protected;

  GitBranch({
    required this.name,
    required this.commit,
    required this.protected,
  });

  factory GitBranch.fromJson(Map<String, dynamic> json) =>
      _$GitBranchFromJson(json);

  Map<String, dynamic> toJson() => _$GitBranchToJson(this);
}

@JsonSerializable()
class CommitData {
  final String sha;
  final String url;
  final CommitBean commit;

  CommitData({
    required this.sha,
    required this.url,
    required this.commit,
  });

  factory CommitData.fromJson(Map<String, dynamic> json) =>
      _$CommitDataFromJson(json);

  Map<String, dynamic> toJson() => _$CommitDataToJson(this);
}

@JsonSerializable()
class CommitBean {
  final String message;
  final CommitAuthor author;
  final CommitAuthor committer;

  CommitBean({
    required this.message,
    required this.author,
    required this.committer,
  });

  factory CommitBean.fromJson(Map<String, dynamic> json) =>
      _$CommitBeanFromJson(json);

  Map<String, dynamic> toJson() => _$CommitBeanToJson(this);
}

@JsonSerializable()
class CommitAuthor {
  final String name;
  final String email;
  final String date;

  CommitAuthor({
    required this.name,
    required this.email,
    required this.date,
  });

  factory CommitAuthor.fromJson(Map<String, dynamic> json) =>
      _$CommitAuthorFromJson(json);

  Map<String, dynamic> toJson() => _$CommitAuthorToJson(this);
}
